<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: light)">
<meta name="theme-color" content="#222" media="(prefers-color-scheme: dark)"><meta name="generator" content="Hexo 5.4.2">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha256-DfWjNxDkM94fVBWx1H5BMMp0Zq7luBlV8QRcSES7s+0=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"mathieulin.gitee.io","root":"/","images":"/images","scheme":"Gemini","darkmode":true,"version":"8.12.1","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"manual","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="补充板子进制转换10进制转2进制123456789101112131415161718int ten_to_two()&amp;#123;    int num;	int temp;	int i&#x3D;0;    int arr[20];    printf(&quot;请输入一个十进制数：\n&quot;);    scanf(&quot;%d&quot;, &amp;num);        do&amp;#123">
<meta property="og:type" content="article">
<meta property="og:title" content="Mathieu&#39;s blog">
<meta property="og:url" content="https://mathieulin.gitee.io/2023/09/21/%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90/index.html">
<meta property="og:site_name" content="Mathieu&#39;s blog">
<meta property="og:description" content="补充板子进制转换10进制转2进制123456789101112131415161718int ten_to_two()&amp;#123;    int num;	int temp;	int i&#x3D;0;    int arr[20];    printf(&quot;请输入一个十进制数：\n&quot;);    scanf(&quot;%d&quot;, &amp;num);        do&amp;#123">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://mathieulin.gitee.io/.io//myblog/source_posts/补充板子/image-20230922155626744.png">
<meta property="article:published_time" content="2023-09-21T04:30:18.299Z">
<meta property="article:modified_time" content="2023-09-22T08:03:57.545Z">
<meta property="article:author" content="Mathieu Lin">
<meta property="article:tag" content="lzh">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://mathieulin.gitee.io/.io//myblog/source_posts/补充板子/image-20230922155626744.png">


<link rel="canonical" href="https://mathieulin.gitee.io/2023/09/21/%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":true,"permalink":"https://mathieulin.gitee.io/2023/09/21/%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90/","path":"2023/09/21/补充板子/","title":""}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title> | Mathieu's blog</title>
  




<link rel="dns-prefetch" href="https://blog-commeny-mh5e4d5jo-mathieulin.vercel.app">
  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<link rel="alternate" href="/atom.xml" title="Mathieu's blog" type="application/atom+xml">
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">Mathieu's blog</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">lzhow的debug路程</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li><li class="menu-item menu-item-schedule"><a href="/schedule/" rel="section"><i class="fa fa-calendar fa-fw"></i>日程表</a></li><li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li><li class="menu-item menu-item-commonweal"><a href="/404/" rel="section"><i class="fa fa-heartbeat fa-fw"></i>公益 404</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90"><span class="nav-number">1.</span> <span class="nav-text">补充板子</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%9B%E5%88%B6%E8%BD%AC%E6%8D%A2"><span class="nav-number">1.0.1.</span> <span class="nav-text">进制转换</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#10%E8%BF%9B%E5%88%B6%E8%BD%AC2%E8%BF%9B%E5%88%B6"><span class="nav-number">1.0.1.1.</span> <span class="nav-text">10进制转2进制</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2%E8%BF%9B%E5%88%B6%E8%BD%AC10%E8%BF%9B%E5%88%B6"><span class="nav-number">1.0.1.2.</span> <span class="nav-text">2进制转10进制</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%9C%80%E5%A4%A7%E5%AD%90%E6%A0%91%E5%92%8C"><span class="nav-number">1.0.2.</span> <span class="nav-text">最大子树和</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%96%E4%B8%8D%E7%9B%B8%E9%82%BB%E7%9A%84%E6%95%B0"><span class="nav-number">1.0.3.</span> <span class="nav-text">取不相邻的数</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B5%81%E6%B0%B4%E7%BA%BF%E8%B0%83%E5%BA%A6"><span class="nav-number">1.1.</span> <span class="nav-text">流水线调度</span></a></li></ol></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">Mathieu Lin</p>
  <div class="site-description" itemprop="description">这是一个记载了lzhow传奇的一生的博客</div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">14</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
        <span class="site-state-item-count">8</span>
        <span class="site-state-item-name">分类</span>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author site-overview-item animated">
      <span class="links-of-author-item">
        <a href="https://github.com/mathieulin" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;mathieulin" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="mailto:19241032@buaa.edu.cn" title="E-Mail → mailto:19241032@buaa.edu.cn" rel="noopener" target="_blank"><i class="fab fa-envelope fa-fw"></i>E-Mail</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://121.199.35.110/" title="Todo → http:&#x2F;&#x2F;121.199.35.110&#x2F;" rel="noopener" target="_blank">Todo</a>
      </span>
      <span class="links-of-author-item">
        <a href="http://noietch.cn:88/" title="House → http:&#x2F;&#x2F;noietch.cn:88&#x2F;" rel="noopener" target="_blank">House</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-05d97c93-6101-4c53-8659-f5cf79396b93/0cdfad7c-f758-49ca-becf-6483b8fe95d5.apk" title="Douzero → https:&#x2F;&#x2F;vkceyugu.cdn.bspapp.com&#x2F;VKCEYUGU-05d97c93-6101-4c53-8659-f5cf79396b93&#x2F;0cdfad7c-f758-49ca-becf-6483b8fe95d5.apk" rel="noopener" target="_blank">Douzero</a>
      </span>
      <span class="links-of-author-item">
        <a href="/atom.xml" title="rss → &#x2F;atom.xml"><i class="fa fa-rss fa-fw"></i>rss</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://mathieulin.github.io/myblog" title="Another-blog → https:&#x2F;&#x2F;mathieulin.github.io&#x2F;myblog" rel="noopener" target="_blank">Another-blog</a>
      </span>
  </div>



        </div>
      </div>
    </div>
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=86 src="//music.163.com/outchain/player?type=2&id=1951671851&auto=1&height=66"></iframe>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://mathieulin.gitee.io/2023/09/21/%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.gif">
      <meta itemprop="name" content="Mathieu Lin">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Mathieu's blog">
      <meta itemprop="description" content="这是一个记载了lzhow传奇的一生的博客">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content=" | Mathieu's blog">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2023-09-21 12:30:18" itemprop="dateCreated datePublished" datetime="2023-09-21T12:30:18+08:00">2023-09-21</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">更新于</span>
      <time title="修改时间：2023-09-22 16:03:57" itemprop="dateModified" datetime="2023-09-22T16:03:57+08:00">2023-09-22</time>
    </span>

  
  
  <span class="post-meta-item">
    
    <span class="post-meta-item-icon">
      <i class="far fa-comment"></i>
    </span>
    <span class="post-meta-item-text">评论数：</span>
  
    <a title="waline" href="/2023/09/21/%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90/#waline" itemprop="discussionUrl">
      <span class="post-comments-count waline-comment-count" data-path="/2023/09/21/%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90/" itemprop="commentCount"></span>
    </a>
  </span>
  
  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h1 id="补充板子"><a href="#补充板子" class="headerlink" title="补充板子"></a>补充板子</h1><h3 id="进制转换"><a href="#进制转换" class="headerlink" title="进制转换"></a>进制转换</h3><h4 id="10进制转2进制"><a href="#10进制转2进制" class="headerlink" title="10进制转2进制"></a>10进制转2进制</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">ten_to_two</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="type">int</span> num;</span><br><span class="line">	<span class="type">int</span> temp;</span><br><span class="line">	<span class="type">int</span> i=<span class="number">0</span>;</span><br><span class="line">    <span class="type">int</span> arr[<span class="number">20</span>];</span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;请输入一个十进制数：\n&quot;</span>);</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;num);</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">do</span>&#123;</span><br><span class="line">    	temp=num%<span class="number">2</span>;</span><br><span class="line">    	num=num/<span class="number">2</span>;</span><br><span class="line">    	arr[i++]=temp; </span><br><span class="line">    &#125;<span class="keyword">while</span> (num!=<span class="number">0</span>);</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> j = i<span class="number">-1</span>; j&gt;=<span class="number">0</span>; j--)</span><br><span class="line">   		<span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>,arr[j]);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h4 id="2进制转10进制"><a href="#2进制转10进制" class="headerlink" title="2进制转10进制"></a>2进制转10进制</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="title function_">two_to_ten</span><span class="params">()</span> &#123;</span><br><span class="line">	<span class="type">int</span> i, d, a, b, sum = <span class="number">0</span>;</span><br><span class="line">	<span class="type">char</span> str[<span class="number">50</span>];<span class="comment">//字符数组string，长度30</span></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;请输入一个二进制数：\n&quot;</span>);</span><br><span class="line">	<span class="built_in">scanf</span>(<span class="string">&quot;%s&quot;</span>, str);<span class="comment">//输入二进制数</span></span><br><span class="line">	d = <span class="built_in">strlen</span>(str);</span><br><span class="line">	<span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; d; i++) &#123; <span class="comment">//二进制转为十进制要从右到左用二进制的每个数去乘以2的相应次方求和</span></span><br><span class="line">		a = str[i] - <span class="number">48</span>;</span><br><span class="line">		b = <span class="built_in">pow</span>(<span class="number">2</span>, d - <span class="number">1</span> - i); <span class="comment">//2的次方</span></span><br><span class="line">		sum += a * b; <span class="comment">//十进制要从右到左用二进制的每个数去乘以2的相应次方相加</span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>, sum); <span class="comment">//输出十进制整数</span></span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="最大子树和"><a href="#最大子树和" class="headerlink" title="最大子树和"></a>最大子树和</h3><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span> <span class="string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MAX_SIZE 16005</span></span><br><span class="line"><span class="meta">#<span class="keyword">define</span> MIN_VALUE -2147483647</span></span><br><span class="line"></span><br><span class="line"><span class="type">int</span> n, a[MAX_SIZE], f[MAX_SIZE], ans = MIN_VALUE;</span><br><span class="line"><span class="type">int</span>* E[MAX_SIZE];</span><br><span class="line"><span class="type">int</span> size[MAX_SIZE] = &#123;<span class="number">0</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="type">void</span> <span class="title function_">dfs</span><span class="params">(<span class="type">int</span> u, <span class="type">int</span> fa)</span></span><br><span class="line">&#123;</span><br><span class="line">    f[u] = a[u]; <span class="comment">// 初始化 f 的值</span></span><br><span class="line">    <span class="type">int</span> i;</span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">0</span>; i &lt; size[u]; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span> t = E[u][i];</span><br><span class="line">        <span class="keyword">if</span> (t != fa)</span><br><span class="line">        &#123;</span><br><span class="line">            dfs(t, u);</span><br><span class="line">            <span class="keyword">if</span> (f[t] &gt; <span class="number">0</span>)</span><br><span class="line">                f[u] += f[t]; <span class="comment">// 更新点权和</span></span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">max</span><span class="params">(<span class="type">int</span> a, <span class="type">int</span> b)</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="keyword">return</span> (a &gt; b) ? a : b;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span></span><br><span class="line">&#123;</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;n);</span><br><span class="line">    <span class="type">int</span> i;</span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">1</span>; i &lt;= n; i++)</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;a[i]); <span class="comment">// 读入点权</span></span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">1</span>; i &lt; n; i++)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="type">int</span> u, v;</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">&quot;%d%d&quot;</span>, &amp;u, &amp;v);</span><br><span class="line">        </span><br><span class="line">        <span class="comment">// 动态数组存储邻接表</span></span><br><span class="line">        E[u] = (<span class="type">int</span>*)<span class="built_in">realloc</span>(E[u], (size[u] + <span class="number">1</span>) * <span class="keyword">sizeof</span>(<span class="type">int</span>));</span><br><span class="line">        E[u][size[u]++] = v;</span><br><span class="line">        E[v] = (<span class="type">int</span>*)<span class="built_in">realloc</span>(E[v], (size[v] + <span class="number">1</span>) * <span class="keyword">sizeof</span>(<span class="type">int</span>));</span><br><span class="line">        E[v][size[v]++] = u;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    dfs(<span class="number">1</span>, <span class="number">0</span>);</span><br><span class="line"></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">1</span>; i &lt;= n; i++)</span><br><span class="line">        ans = max(ans, f[i]); <span class="comment">// 找出最大点权和</span></span><br><span class="line"></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>, ans);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h3 id="取不相邻的数"><a href="#取不相邻的数" class="headerlink" title="取不相邻的数"></a>取不相邻的数</h3><p><strong>一个 <em>N</em> × <em>M</em> 的由非负整数构成的数字矩阵，你需要在其中取出若干个数字，使得取出的任意两个数字不相邻（若一个数字在另外一个数字相邻 8 个格子中的一个即认为这两个数字相邻），求取出数字和最大是多少</strong></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;bits/stdc++.h&gt;</span><span class="comment">//万能头文件 </span></span></span><br><span class="line">using namespace <span class="built_in">std</span>;</span><br><span class="line"><span class="type">const</span> <span class="type">int</span> d[<span class="number">8</span>][<span class="number">2</span>]=&#123;<span class="number">1</span>,<span class="number">0</span>,<span class="number">-1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">-1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">-1</span>,<span class="number">1</span>,<span class="number">1</span>,<span class="number">-1</span>,<span class="number">-1</span>,<span class="number">-1</span>&#125;;<span class="comment">//方向数组用来控制搜索时的方向 </span></span><br><span class="line"><span class="type">int</span> t,n,m,s[<span class="number">8</span>][<span class="number">8</span>],mark[<span class="number">8</span>][<span class="number">8</span>],ans,mx;</span><br><span class="line"><span class="type">void</span> <span class="title function_">dfs</span><span class="params">(<span class="type">int</span> x,<span class="type">int</span> y)</span>&#123;<span class="comment">//搜索函数，表示搜索点(x,y) </span></span><br><span class="line">	<span class="keyword">if</span>(y==m+<span class="number">1</span>)&#123;<span class="comment">//当y到边界时，搜索下一行 </span></span><br><span class="line">		dfs(x+<span class="number">1</span>,<span class="number">1</span>);</span><br><span class="line">		<span class="keyword">return</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">if</span>(x==n+<span class="number">1</span>)&#123;<span class="comment">//当x到边界时，搜索结束，刷新最大值 </span></span><br><span class="line">		mx=max(ans,mx);</span><br><span class="line">		<span class="keyword">return</span>;</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">	dfs(x,y+<span class="number">1</span>);<span class="comment">// 不取此数的情况 </span></span><br><span class="line">	</span><br><span class="line">	<span class="keyword">if</span>(mark[x][y]==<span class="number">0</span>)&#123; <span class="comment">//取此数的情况（需保证此数周围没有取其他数，即mark[i][j]==0）</span></span><br><span class="line">		ans+=s[x][y];</span><br><span class="line">		<span class="keyword">for</span>(<span class="type">int</span> fx=<span class="number">0</span>;fx&lt;<span class="number">8</span>;++fx)&#123; <span class="comment">//标记周围的数 </span></span><br><span class="line">			++mark[x+d[fx][<span class="number">0</span>]][y+d[fx][<span class="number">1</span>]];</span><br><span class="line">		&#125;</span><br><span class="line">		dfs(x,y+<span class="number">1</span>);</span><br><span class="line">		<span class="keyword">for</span>(<span class="type">int</span> fx=<span class="number">0</span>;fx&lt;<span class="number">8</span>;++fx)&#123; <span class="comment">//回溯 </span></span><br><span class="line">			--mark[x+d[fx][<span class="number">0</span>]][y+d[fx][<span class="number">1</span>]];</span><br><span class="line">		&#125;</span><br><span class="line">		ans-=s[x][y];</span><br><span class="line">	&#125;</span><br><span class="line">	</span><br><span class="line">&#125;</span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span>&#123;</span><br><span class="line">	<span class="built_in">cin</span>&gt;&gt;t; </span><br><span class="line">	<span class="keyword">while</span>(t--)&#123;</span><br><span class="line">		<span class="built_in">memset</span>(s,<span class="number">0</span>,<span class="keyword">sizeof</span>(s));</span><br><span class="line">		<span class="built_in">memset</span>(mark,<span class="number">0</span>,<span class="keyword">sizeof</span>(mark));<span class="comment">//在做每个数据前都要初始化数组 </span></span><br><span class="line">		<span class="built_in">cin</span>&gt;&gt;n&gt;&gt;m;</span><br><span class="line">		<span class="keyword">for</span>(<span class="type">int</span> i=<span class="number">1</span>;i&lt;=n;++i)&#123;</span><br><span class="line">			<span class="keyword">for</span>(<span class="type">int</span> j=<span class="number">1</span>;j&lt;=m;++j)&#123;</span><br><span class="line">				<span class="built_in">cin</span>&gt;&gt;s[i][j];</span><br><span class="line">			&#125;</span><br><span class="line">		&#125;</span><br><span class="line">		mx=<span class="number">0</span>;</span><br><span class="line">		dfs(<span class="number">1</span>,<span class="number">1</span>);<span class="comment">//从点(1,1)开始搜索 </span></span><br><span class="line">		<span class="built_in">printf</span>(<span class="string">&quot;%d\n&quot;</span>,mx);<span class="comment">//输出答案 </span></span><br><span class="line">	&#125;</span><br><span class="line">	<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>



<h2 id="流水线调度"><a href="#流水线调度" class="headerlink" title="流水线调度"></a>流水线调度</h2><p><img src="/.io//myblog\source_posts\补充板子\image-20230922155626744.png" alt="image-20230922155626744"></p>
<figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;stdio.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;math.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;string.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="keyword">include</span><span class="string">&lt;stdlib.h&gt;</span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="type">long</span> <span class="type">long</span> ll;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 定义一个结构体TW，表示一个摊位的游戏所需时间。</span></span><br><span class="line"><span class="comment">// a代表路北摊位需要的时间，b代表路南摊位需要的时间。</span></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> &#123;</span></span><br><span class="line">    <span class="type">int</span> a;</span><br><span class="line">    <span class="type">int</span> b;</span><br><span class="line">&#125; TW;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 自定义一个max函数，返回两个整数中的较大值。</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">max</span><span class="params">(<span class="type">int</span> a, <span class="type">int</span> b)</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> a &gt; b ? a : b;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 定义三个TW类型的数组。</span></span><br><span class="line"><span class="comment">// tw用于存储输入的n个摊位。</span></span><br><span class="line"><span class="comment">// tw1用于存储那些路北摊位游戏时间比路南摊位短的摊位。</span></span><br><span class="line"><span class="comment">// tw2用于存储其它摊位。</span></span><br><span class="line">TW tw[<span class="number">1005</span>], tw1[<span class="number">1005</span>], tw2[<span class="number">1005</span>];</span><br><span class="line"><span class="comment">// sum1用于记录在特定顺序下，到达每个摊位时的累计时间。</span></span><br><span class="line"><span class="comment">// sum2用于记录完成每个摊位游戏后的最短累计时间。</span></span><br><span class="line"><span class="type">int</span> sum1[<span class="number">1005</span>], sum2[<span class="number">1005</span>];</span><br><span class="line"></span><br><span class="line"><span class="comment">// 比较函数，用于将tw2中的摊位按照路南摊位所需时间从大到小排序。</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">cmp</span><span class="params">(<span class="type">const</span> <span class="type">void</span> *a, <span class="type">const</span> <span class="type">void</span> *b)</span> &#123;</span><br><span class="line">    TW *p = (TW *)a;</span><br><span class="line">    TW *q = (TW *)b;</span><br><span class="line">    <span class="keyword">return</span> q-&gt;b - p-&gt;b;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 比较函数，用于将tw1中的摊位按照路北摊位所需时间从小到大排序。</span></span><br><span class="line"><span class="type">int</span> <span class="title function_">cmp2</span><span class="params">(<span class="type">const</span> <span class="type">void</span> *a, <span class="type">const</span> <span class="type">void</span> *b)</span> &#123;</span><br><span class="line">    TW *p = (TW *)a;</span><br><span class="line">    TW *q = (TW *)b;</span><br><span class="line">    <span class="keyword">return</span> p-&gt;a - q-&gt;a;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="title function_">main</span><span class="params">()</span> &#123;</span><br><span class="line">    <span class="type">int</span> n;</span><br><span class="line">    <span class="type">int</span> i, j = <span class="number">0</span>, k = <span class="number">0</span>;</span><br><span class="line">    <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;n);  <span class="comment">// 读取摊位数量n</span></span><br><span class="line">    <span class="comment">// 读取每个摊位的路北游戏时间</span></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">1</span>; i &lt;= n; i++) &#123;</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;tw[i].a);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 读取每个摊位的路南游戏时间，并按照路北和路南的游戏时间将它们分类到tw1和tw2中</span></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">1</span>; i &lt;= n; i++) &#123;</span><br><span class="line">        <span class="built_in">scanf</span>(<span class="string">&quot;%d&quot;</span>, &amp;tw[i].b);</span><br><span class="line">        <span class="keyword">if</span> (tw[i].a &lt; tw[i].b) &#123;</span><br><span class="line">            tw1[++j] = tw[i];</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            tw2[++k] = tw[i];</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 对tw1和tw2进行排序</span></span><br><span class="line">    qsort(tw1 + <span class="number">1</span>, j, <span class="keyword">sizeof</span>(TW), cmp2);</span><br><span class="line">    qsort(tw2 + <span class="number">1</span>, k, <span class="keyword">sizeof</span>(TW), cmp);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 初始化累计时间数组</span></span><br><span class="line">    sum1[<span class="number">0</span>] = <span class="number">0</span>, sum2[<span class="number">0</span>] = <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 更新在访问tw1中的摊位后的累计时间</span></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">1</span>; i &lt;= j; i++) &#123;</span><br><span class="line">        sum1[i] = sum1[i - <span class="number">1</span>] + tw1[i].a;</span><br><span class="line">        sum2[i] = max(sum1[i], sum2[i - <span class="number">1</span>]) + tw1[i].b;</span><br><span class="line">    &#125;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 更新在访问tw2中的摊位后的累计时间</span></span><br><span class="line">    <span class="keyword">for</span> (i = <span class="number">1</span>; i &lt;= k; i++) &#123;</span><br><span class="line">        sum1[i + j] = sum1[i + j - <span class="number">1</span>] + tw2[i].a;</span><br><span class="line">        sum2[i + j] = max(sum1[i + j], sum2[i + j - <span class="number">1</span>]) + tw2[i].b;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 输出最短完成所有游戏的总时间</span></span><br><span class="line">    <span class="built_in">printf</span>(<span class="string">&quot;%d&quot;</span>, sum2[n]);</span><br><span class="line">    <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br></pre></td></tr></table></figure>


    </div>

    
    
    

    <footer class="post-footer"><script src="//sdk.jinrishici.com/v2/browser/jinrishici.js"></script>
<script>
  jinrishici.load((result) => {
    let jrsc = document.getElementById('jrsc');
    const data = result.data;
    let author = data.origin.author;
    let title = '《' + data.origin.title + '》';
    let content = data.content.substr(0, data.content.length - 1);
    let dynasty = data.origin.dynasty.substr(0, data.origin.dynasty.length - 1);
    jrsc.innerText = content + ' @ ' + dynasty + '·' + author + title;
  });
</script>
<div style="text-align: center"><span id="jrsc" >正在加载今日诗词....</span></div>


        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2023/08/29/%E4%BF%9D%E7%A0%94%E9%9D%A2%E8%AF%95/" rel="prev" title="保研面试">
                  <i class="fa fa-chevron-left"></i> 保研面试
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2023/09/22/super2121/" rel="next" title="">
                   <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






    <div class="comments" id="waline"></div>
</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Mathieu Lin</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div><script color="0,0,255" opacity="0.5" zIndex="-1" count="99" src="https://cdnjs.sourcegcdn.com//ajax/libs/canvas-nest.js/1.0.1/canvas-nest.js"></script>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.5.0/pjax.min.js" integrity="sha256-3NkoLDrmHLTYj7csHIZSr0MHAFTXth7Ua/DDt4MRUAg=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  
<script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.0/search.js" integrity="sha256-vXZMYLEqsROAXkEw93GGIvaB2ab+QW6w3+1ahD9nXXA=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>





  




<script class="next-config" data-name="waline" type="application/json">{"lang":"zh-CN","enable":true,"serverURL":"https://blog-commeny-mh5e4d5jo-mathieulin.vercel.app","cssUrl":"https://unpkg.com/@waline/client@v2/dist/waline.css","commentCount":true,"pageview":false,"el":"#waline","comment":true,"libUrl":"//unpkg.com/@waline/client@v2/dist/waline.js","path":"/2023/09/21/%E8%A1%A5%E5%85%85%E6%9D%BF%E5%AD%90/"}</script>
<link rel="stylesheet" href="https://unpkg.com/@waline/client@v2/dist/waline.css">
<script>
document.addEventListener('page:loaded', () => {
  NexT.utils.loadComments(CONFIG.waline.el).then(() =>
    NexT.utils.getScript(CONFIG.waline.libUrl, { condition: window.Waline })
  ).then(() => 
    Waline.init(Object.assign({}, CONFIG.waline,{ el: document.querySelector(CONFIG.waline.el) }))
  );
});
</script>

</body>
</html>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>
